package A1;

/**
 * Created by IntelliJ IDEA.
 * User: Ferdy
 * Date: 31 Mar 11
 * Time: 13:57:57
 * To change this template use File | Settings | File Templates.
 */
/**main menu*/
public class MainUI {
    Model pm = new Model();

    public void menu(){





        System.out.print("=== MENU ===\n"+
                "1. Set Number of horizontal lanes (H-street) [min 1, max 3]\n"+
                "2. Set Number of vertical lanes  (V-street) [min 1, max 4]\n"+
                "3. Set Probability of a car entering H-street [min 0, max 1]\n"+
                "4. Set Probability of a car entering V-street [min 0, max 1]\n"+
                "5. Run one simulation cycle\n"+
                "6. Set and run number of simulation cycles [min 1, max 10]\n"+
                "7. Exit program\n");
        String choice=GetUserInput.userChoice("Enter your choice: ");
        int choiceInt=Integer.parseInt(choice);

        switch(choiceInt){
            case 1:
                System.out.println("Menu 1");
                setHorLane();
                break;
            case 2:
                System.out.println("Menu 2");
                setVerLane();
                break;
            case 3:
                System.out.println("Menu 3");
                setHorCar();
                break;
            case 4:
                System.out.println("Menu 4");
                setVerCar();
                break;
            case 5:
                System.out.println("Menu 5");
                setRun();
                break;
            case 6:
                System.out.println("Menu 6");
                setRunTimes();
                break;
            case 7:
                System.out.println("Thank You!");
                System.exit(1);
                break;
            default:
                System.out.println("Error! Please enter number between 1-6\n");
                menu();
        }

    }

    /**set horizontal lane*/
    public void setHorLane(){
        String choice=GetUserInput.userChoice("Choose the number of horizontal lane (1-3): ");
        int userChoiceInt=Integer.parseInt(choice);
        int min=1;
        int max=3;

          if(userChoiceInt>max||userChoiceInt<min)
        {System.out.println("Error! Please enter number between 1 to 3");
        setHorLane();}
          else
             {pm.setHorLane(choice);
                 if(pm.getVerLane()!=0){pm.setCell();}
              System.out.println("");
              menu();}
    }

    /**set vertical lane*/
    public void setVerLane(){
        String choice=GetUserInput.userChoice("Choose the number of vertical lane (1-4): ");
        int userChoiceInt=Integer.parseInt(choice);
        int min=1;
        int max=4;

          if (userChoiceInt>max||userChoiceInt<min)
        {System.out.print("Error! Please enter number between 1 to 4");
        setVerLane();}
          else
            {pm.setVerLane(choice);
                if(pm.getHorLane()!=0){pm.setCell();}
             System.out.println("");
             menu();}
    }

    /**set probability of horizontal car*/
    public void setHorCar(){
        String choice=GetUserInput.userChoice("Choose the probability of car in horizontal lane (0-1)");
        double userChoiceDouble=Double.parseDouble(choice);
        double min=0;
        double max=1;

          if (userChoiceDouble<min||userChoiceDouble>max)
        {System.out.print("Error! Please enter number between 0 to 1");
        setHorCar();}
          else
            {pm.setHorCar(userChoiceDouble);
             System.out.println("");
             menu();}
        }

    /**set probability of vertical car*/
    public void setVerCar(){
        String choice=GetUserInput.userChoice("Choose the probability of car in vertical lane (0-1)");
        double userChoiceDouble=Double.parseDouble(choice);
        double min=0;
        double max=1;

          if (userChoiceDouble<min||userChoiceDouble>max)
        {System.out.print("Error! Please enter number between 0 to 1");
        setVerCar();}
          else
            {pm.setVerCar(userChoiceDouble);
             System.out.println("");
             menu();}

    }

    /**run simulation once*/
    public void setRun(){
        pm.setUserRun(1);
        pm.setGrid();
        menu();

    }

    /**run simulation based on the user input*/
    public void setRunTimes(){
        String choice=GetUserInput.userChoice("Choose the times of program runs (1-10): ");
        int userChoiceInt=Integer.parseInt(choice);
        int min=1;
        int max=10;

          if(userChoiceInt>max||userChoiceInt<min)
        {System.out.println("Error! Please enter number between 1 to 10");
        setRunTimes();}
          else
          {
              pm.setUserRun(userChoiceInt);
              pm.setGrid();              
              menu();}
    }
    

}
